<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>

            $(function(){
               //当前页的input框
                var currentInput = $("#currentPage");
                //用于储存数据的数据
                var Arr = [];
                //总页数
                var pages = 1;
                function query(href,fun) {
                    //获取当前页的值
                    var currentPage = currentInput.val();//1
                    $.get(href,{currentPage:currentPage,pageSize:3}, function (data) {
                        console.log(data);
                        //合并两个数组到第一个参数数组上
                        $.merge( Arr, data.list );
                        //用于渲染时循环,循环时是取list的属性出来
                        var json = {
                            list:Arr
                        };
                        //渲染数据
                         fun(json);
                        //设置总页数
                        pages = data.pages;
                    })
                    //当前页input框+1
                    currentInput.val(parseInt(currentPage)+1);
                }

                var user = JSON.parse(sessionStorage.getItem('user'));
                var strategyHref = '/collects/'+user.id+'/strategy';
                var travelHref = '/collects/'+user.id+'/travel';
                var dailyNewsHref='/collects/'+user.id+'/dailyNews';

                function strategy(data){
                    $("#pills-strategy").renderValues(data,{
                        getHref:getHref
                    });
                }
                function travel(data){
                    $("#pills-travel").renderValues(data, {
                        getHref: getHref
                    });
                }
                function dailyNews(data){
                    //console.log(data);
                    $("#pills-dailyNews").renderValues(data, {
                        getHref: getHref
                    });
                }

                var judge = 1;
                query(strategyHref,strategy);

                $('#pills-top-travel').click(function () {
                    currentInput.val(1);
                    Arr = [];
                    query(travelHref,travel);
                    judge = 2;
                })

                $('#pills-top-dailyNews').click(function () {
                    currentInput.val(1);
                    Arr = [];
                    query(dailyNewsHref,dailyNews);
                    judge = 3;
                })

                //当页面滚动条变化时，执行的函数
                $(window).scroll( function() {
                    if($(document).scrollTop()+$(window).height()>=$(document).height()-1){
                        var currentPage = currentInput.val();
                        //判断是否小于或等于最后一页,如果是就去查询
                        if(currentPage<=pages) {
                            if (judge == 1) {
                                query(strategyHref,strategy);
                            }else if(judge ==2) {
                                query(travelHref,travel);
                            }else if(judge ==3) {
                                query(dailyNewsHref,dailyNews);
                            }
                        }else{
                            $(document).dialog({
                                type : 'notice',
                                infoText: '快去收藏更多吧!',
                                autoClose: 1000
                            });
                        }
                    }
                });


            })
    </script>
</head>

<body>
<!--从第二页开始-->
<input type="hidden" name="currentPage" id="currentPage" value="1">

<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的收藏</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-collect" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" id="pills-top-strategy" data-toggle="pill" href="#pills-strategy">
            <span style="font-weight: bold;">攻略</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link" id="pills-top-travel" data-toggle="pill" href="#pills-travel">
            <span style="font-weight: bold;">游记</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link" id="pills-top-dailyNews" data-toggle="pill" href="#pills-dailyNews">
            <span style="font-weight: bold;">日报</span>
        </a>
    </li>
</ul>
<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-strategy">
        <div class="container commend" render-loop="list">
            <a data-href="../strategyCatalogs.html?strategyId=" render-key="list.strategy.id" render-fun="getHref">
                <p render-html="list.strategy.title"></p>
                <img render-src="list.strategy.coverUrl">
                <p>收藏时间 <span render-html="list.createTime"></span>
                </p>
            </a>
        </div>
    </div>

    <div class="tab-pane fade" id="pills-travel">
        <div class="container travels" >
        <dl class="list" render-loop="list">
            <dd>
                <a data-href="../travelContent.html?id=" render-key="list.travel.id" render-fun="getHref">
                    <img render-src="list.travel.coverUrl"width="300px" >
                    <h6 class="title" render-html="list.travel.title"> </h6>
                    <p>收藏时间 <span render-html="list.createTime"></span>
                    </p>
                </a>
            </dd>
        </dl>
        </div>
    </div>

    <div class="tab-pane fade" id="pills-dailyNews">
        <div class="container dailyNews" >
            <dl class="list" render-loop="list">
                <dd>
                    <a data-href="/newsContent.html?news_id=" render-key="list.dailyNews.id" render-fun="getHref">
                        <img render-src="list.dailyNews.coverImgUrl"width="300px" >
                        <h6 class="title" render-html="list.dailyNews.title"> </h6>
                        <p>收藏时间 <span render-html="list.createTime"></span>
                        </p>
                    </a>
                </dd>
            </dl>
        </div>
    </div>
</div>


</body>

</html>


